<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","kurssi_id");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_currsirate.php";
$FileTemplate  = "ais_transaction_currsirate_list.html";
$TableName     = "ais_kurssi";
$SubHeaderTitle= "Transaction Currency Rate - Rate of days";
$PageSize      = 10 ;
$HTMLGridList  = "CurrencyGrid";
//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

//Initiate Database Table For Search;
$FDate = GetParam("currDateSearch","");
$FCurrency = GetParam("currCodeSearch","");

//******* DATABASE FORM QUERY ***********
$SQL = "SELECT * FROM `$TableName` LEFT JOIN tblcurrency ON $TableName.curr=tblcurrency.tusymbol";
$SQLCount = "SELECT count(*) FROM `$TableName` ";

if ($FDate) {
	list($d,$m,$y) = explode('/',$FDate);
	$FDate_f = $y . '-' . $m . '-' . $d;
	if (strlen($WHERE)) $WHERE .= " AND "." tglbkt = '".$FDate_f."%'";
	else $WHERE .= " tglbkt = '".$FDate_f."'";	
}

if ($FCurrency) 
	if (strlen($WHERE)) $WHERE .= " AND "." curr = '".$FCurrency."'";
	else $WHERE .= " curr = '".$FCurrency."'";

	if (strlen($WHERE))	$WHERE = " WHERE ".$WHERE." AND ".QueryLedger();
	else $WHERE = " WHERE 1";

$SQL = $SQL.$WHERE." ORDER BY tglbkt DESC";
//print $SQL;
//Select Department 
$SQLCurr = "SELECT * FROM tblcurrency";

//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("currblk",$DBMysql,$SQLCurr);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName;	
	for ($x=1;$x<=$PageSize;$x++) {		
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("tblcurrency",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>
